package Offer.offer2017;

/**
 * 打印1到最大的N位数,递归全排列的方式
 * Created by 雷文康 on 2017/12/30.
 */
public class Test12a {
    public static void main(String[] args) {
        printToN(2);
    }
    public static void printToN(int n){
        if (n <= 0){
            return;
        }
        int[] array = new int[n];
        printToN(array, 0 );
    }

    private static void printToN(int[] array, int start){
        if (start == array.length){
            print(array);
            return;
        }
        //先设置最高位的值
        for (int i = 0; i < 10; i++) {
            array[start] = i;
            printToN(array, start+1 );
        }
    }

    private static void print(int[] array){
        int i;
        for (i = 0; i < array.length; i++) {
            if (array[i] != 0){
                break;
            }
        }
        while (i < array.length){
            System.out.print(array[i++]);
        }
        System.out.print(" ");
    }
}
